const jwt = require('koa-jwt')
const Router = require('koa-router')
const router = new Router({ prefix: '/questions/:questionId/answers/:answerId/comments' })
// 导入控制器
const {
  find, findById, create, update,delete:del,
  checkCommentExist, checkCommentator

} = require('../controllers/comments')
// 引入密钥
const { secret } = require('../config')

// 认证中间件
const auth = jwt({ secret })
router.get('/', find)
router.post('/', auth, create)
router.get('/:id', checkCommentExist, findById)
router.patch('/:id', auth, checkCommentExist,checkCommentator, update)
router.delete('/:id', auth, checkCommentExist, checkCommentator, del)
module.exports = router


